import { eventEmitter } from '@/common/message';

export * from './handleLoginExpire';
export * from './handleTokenExpire';
export * from './handleLoginAgain';

export const handleSuccess = (_, res) => {
  if (res.data.message && res.data.message !== 'success') {
    eventEmitter.emit('API:SUCCESS', res.data.message);
  }

  return res.data?.data || res.data;
};

export const handleException = (_, error) => {
  if (error.data.message && error.data.message !== 'success') {
    eventEmitter.emit('API:ERROR', error.data.message);
  }
  return Promise.reject(error);
};
